package com.tianji.learning.controller;


import com.tianji.common.domain.dto.PageDTO;
import com.tianji.learning.domain.dto.QuestionFormDTO;
import com.tianji.learning.domain.query.QuestionPageQuery;
import com.tianji.learning.domain.vo.QuestionVO;
import com.tianji.learning.service.IInteractionQuestionService;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 互动提问的问题表 前端控制器
 * </p>
 *
 * @author dayu
 * @since 2024-08-25
 */
@RestController
@RequestMapping("questions")
@RequiredArgsConstructor
public class InteractionQuestionController {

  private final IInteractionQuestionService questionService;

  @ApiOperation("新增提问")
  @PostMapping
  public void saveQuestion(@Valid @RequestBody QuestionFormDTO questionDTO){
    questionService.saveQuestion(questionDTO);
  }
  @ApiOperation("分页查询互动问题")
  @GetMapping("page")
  public PageDTO<QuestionVO> queryQuestionPage(QuestionPageQuery query){
    return questionService.queryQuestionPage(query);
  }

  @ApiOperation("根据id查询问题详情")
  @GetMapping("{id}")
  public QuestionVO getQuestionById(@PathVariable("id") Long questionId){
   return questionService.getQuestionById(questionId);
  }

  @ApiOperation("修改问题")
  @PutMapping("{id}")
  public void updateQuestion(@PathVariable("id") Long questionId,@Valid @RequestBody QuestionFormDTO questionDTO){
    questionService.updateQuestion(questionId,questionDTO);
  }
  @ApiOperation("删除问题")
  @DeleteMapping("{id}")
  public void delQuestionById(@PathVariable("id") Long questionId){
    questionService.delQuestionById(questionId);
  }
}
